import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
//import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.sql.*;

public class ViewAnyEmpProf extends JFrame {

	private static final long serialVersionUID = 1L;
	private JButton ok;
	private JPanel ePane;
	ImageIcon ii = new ImageIcon(this.getClass().getResource("images/viewprofbg.png"));
	private Image bgImage = ii.getImage();
	private viEmpProfPane viewEPro = new viEmpProfPane();

	public ViewAnyEmpProf(){
		
		setTitle("View Profile");
        //construct components
    	ePane =  new JPanel() {
			private static final long serialVersionUID = 1L;

			protected void paintComponent(Graphics g){
				g.drawImage(bgImage, 0, 0, null);
				super.paintComponent(g);
			}
		};
		
		ok = new JButton ("Ok");
		
        /***GUI CODE FOR VIEW PROFILE****/
        
        //add components
        ePane.add(ok);
        ePane.setSize(585,440);
        ePane.setOpaque(false);
        ePane.setLayout(null);
        ePane.setVisible(true);
        ePane.add(viewEPro);
        
        add(ePane);
        setPreferredSize (new Dimension (585, 435));
        setLayout (null);
        setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setLocationRelativeTo(null);
		
        //set component bounds (only needed by Absolute Positioning)
        ok.setBounds (415, 360, 100, 25);
        
        ok.setForeground(Color.WHITE);
		ok.setBackground(Color.BLACK);
		
		ok.addActionListener(new ActionListener(){
    		public void actionPerformed(ActionEvent e){
    			
    			MainPanel.goToPage(3);
    			setVisible(false);
    		}
    	});
	}
	
	public viEmpProfPane getPane(){
		return viewEPro;
	}
}

class viEmpProfPane extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel uslabel, fullabel, blabel, adlabel, clabel, userid, slabel, fullname, bDate, cnum, status, bslabel, baseSal;
	private JTextArea address;
	private static int uID;
		
	Connection conn = null;

	viEmpProfPane(){
			
			uslabel = new JLabel ("UserID:");
		    fullabel = new JLabel ("Full name:");
		    blabel = new JLabel ("Birthdate:");
		    adlabel = new JLabel ("Address:");
		    clabel = new JLabel ("Contact no.:");
		    bslabel = new JLabel ("Base Salary:");
		    slabel = new JLabel ("Status:");
		    
		    userid = new JLabel ("");
		    address = new JTextArea (5, 5);
		    fullname = new JLabel ("");
		    bDate = new JLabel ("");
		    cnum = new JLabel ("");
		    baseSal = new JLabel ("");
		    status = new JLabel ("");
		    
		    uslabel.setBounds (40, 85, 50, 25);
	        fullabel.setBounds (40, 105, 75, 25);
	        blabel.setBounds (40, 130, 70, 25);
	        adlabel.setBounds (40, 155, 65, 25);
	        clabel.setBounds (45, 235, 80, 25);
	        userid.setBounds (90, 85, 100, 25);
	        bslabel.setBounds (45, 260, 80, 25);
	        slabel.setBounds (45, 285, 55, 25);
	        
	        address.setBounds (100, 160, 175, 75);
	        fullname.setBounds (105, 105, 150, 25);
	        bDate.setBounds (105, 130, 135, 25);
	        cnum.setBounds (120, 235, 115, 25);
	        baseSal.setBounds (130, 260, 110, 25);
	        status.setBounds (90, 285, 110, 25);
	        
	        uslabel.setForeground(Color.WHITE);
		    fullabel.setForeground(Color.WHITE);
		    blabel.setForeground(Color.WHITE);
		    adlabel.setForeground(Color.WHITE);
		    clabel.setForeground(Color.WHITE);
		    userid.setForeground(Color.WHITE);
		    slabel.setForeground(Color.WHITE);
		    fullname.setForeground(Color.WHITE);
		    bDate.setForeground(Color.WHITE);
		    cnum.setForeground(Color.WHITE);
		    status.setForeground(Color.WHITE);
		    bslabel.setForeground(Color.WHITE);
		    baseSal.setForeground(Color.WHITE);
		    
		    add (uslabel);
		    add (fullabel);
		    add (blabel);
		    add (adlabel);
		    add (clabel);
		    add (userid);
		    add (slabel);
		    add (address);
		    add (fullname);
	 	    add (bDate);
		    add (cnum);
		    add (status);
		    add (bslabel);
		    add (baseSal);
		    
		    setSize(585, 435);
			setLayout(null);
			setOpaque(false);
			setVisible(true);
	        
	}

	public void searchProf(){

		try
		{
			ConnectionFactory myFactory = ConnectionFactory.getFactory();
			Connection conn = myFactory.getConnection();
			
			Statement stat = conn.createStatement();
	    
			ResultSet res = stat.executeQuery("SELECT concat(firstName, ' ', middleInitial, ' ', lastName) as 'Full Name', contactNum," +
	    		"DATE_FORMAT(bDate,'%M %e, %Y') as 'Birthdate', address, status, baseSalary FROM bernalcompany.employee WHERE idemployee ="+uID);
	           
	        if(res.next()){
		    	
			    address.setLineWrap(true);
			    address.setText(res.getString("address"));
			    address.setWrapStyleWord(true);
			    userid.setText(String.valueOf(uID));
			    baseSal.setText(res.getString("baseSalary"));
			    fullname.setText(res.getString("Full Name"));
			    bDate.setText(res.getString("Birthdate"));
			    cnum.setText(res.getString("contactNum"));
			    status.setText(res.getString("status"));
			    address.setEditable(false);
	    
			}
			else
				System.out.println("di gumana :(");
			
		    conn.close();
	
		}catch(Exception ex){
			ex.printStackTrace();
			}
	}
	
	public static void setUID(int userID){
		uID = userID;
	}
	public static int getUID(){
		return uID;
	}
}


